package com.tn.rtdata.jmx;

import java.util.Date;
import java.util.List;

import org.apache.commons.lang.builder.EqualsBuilder;
import org.apache.commons.lang.builder.HashCodeBuilder;
import org.apache.commons.lang.builder.ToStringBuilder;
import org.apache.commons.lang.builder.ToStringStyle;

/**
 * An bean that represents a session.
 */
public class Session
{
  private String id;
  private List<FillIdentity> fills;
  private Date lastHeartbeat;

  /**
   * Creates a new <code>Session</code> initialized with the <code>id</code> and <code>fills</code>.
   */
  public Session(String id, Date lastHeartbeat, List<FillIdentity> fills)
  {
    this.id = id;
    this.lastHeartbeat = lastHeartbeat;
    this.fills = fills;
  }

  /**
   * Returns the session id.
   */
  public String getId()
  {
    return id;
  }

  /**
   * Returns the last heartbeat.
   */
  public Date getLastHeartbeat()
  {
    return lastHeartbeat;
  }

  /**
   * Returns the session id.
   */
  public List<FillIdentity> getFills()
  {
    return fills;
  }

  /**
   * Compares this object to another for equality.  For another object to be considered equal to a <code>Session</code> the other object
   * must be a <code>Session</code> and must have been initialized with the same values.
   *
   * @param other the other object.
   *
   * @return <code>true</code> if the objects are considered equal, otherwise <code>false</code>.
   */
  @Override
  public boolean equals(Object other)
  {
    return this == other || other != null && getClass() == other.getClass() &&
      new EqualsBuilder()
        .append(getId(), ((Session)other).getId())
        .append(getFills(), ((Session) other).getFills())
        .isEquals();
  }

  /**
   * {@inheritDoc}
   */
  @Override
  public int hashCode()
  {
    return new HashCodeBuilder()
      .append(getId())
      .append(getFills())
      .toHashCode();
  }

  /**
   * {@inheritDoc}
   */
  @Override
  public String toString()
  {
    return new ToStringBuilder(this, ToStringStyle.SHORT_PREFIX_STYLE)
      .append("id", getId())
      .append("fills", getFills())
      .toString();
  }
}
